import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:osc/res/dimens.dart';
import 'package:osc/utils/string_util.dart';

import '../small_widgets.dart';

typedef CommentBarCallback({bool showInputWidget, bool jump2CommentList, bool reverseFavorite});

class ProjectCommentBarWidget extends StatelessWidget {
  final int id;
  final int commentCount;
  final bool favorite;
  final String comment;
  final CommentBarCallback callback;

  const ProjectCommentBarWidget({Key key, @required this.id, @required this.commentCount, @required this.favorite, @required this.callback, this.comment = ""}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: Dimens.gap_view_biggest, vertical: Dimens.gap_view_small),
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border(top: BorderSide(color: Colors.black12, width: Dimens.gap_divider_height_smallest)),
      ),
      child: Row(
        children: <Widget>[
          Expanded(
              child: InkWell(
                onTap: (){
                  if(callback != null){
                    callback(showInputWidget: true, jump2CommentList: false, reverseFavorite: false);
                  }
                },
                child: Container(
                  alignment: Alignment.centerLeft,
                  margin: EdgeInsets.only(right: Dimens.gap_view_biggest, top: Dimens.gap_view_smallest, bottom: Dimens.gap_view_smallest),
                  padding: EdgeInsets.symmetric(horizontal: Dimens.gap_view_small),
                  height: Dimens.view_item_height_smallest,
                  decoration: BoxDecoration(
                    border: Border.all(color: Colors.black12),
                    borderRadius: BorderRadius.circular(Dimens.view_radius_size_small),
                  ),
                  child: buildText(StringUtil.isEmpty(comment)?"发表评论":comment, StringUtil.isEmpty(comment)? Colors.black26: Colors.black87, Dimens.font_sp12),
                ),
              )
          ),
          InkWell(
            onTap: (){
              if(callback != null){
                callback(showInputWidget: false, jump2CommentList: true, reverseFavorite: false);
              }
            },
            child: Stack(
              children: <Widget>[
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: Dimens.gap_view_normal, vertical: Dimens.gap_view_small),
                  child: SmallWidgets.buildImage(imageName: "ic_comment_30", size: Dimens.view_item_icon_height_small),
                ),
                Positioned(
                  top: 0,
                  right: 0,
                  child: Container(
                    padding: EdgeInsets.symmetric(horizontal: Dimens.gap_view_small, vertical: Dimens.gap_view_smallest),
                    decoration: BoxDecoration(
                      color: Colors.redAccent,
                      borderRadius: BorderRadius.circular(Dimens.view_radius_size_small),
                    ),
                    child: buildText("$commentCount", Colors.white, Dimens.font_sp10),
                  ),
                ),
              ],
            ),
          ),
          InkWell(
            onTap: (){
              if(callback != null){
                callback(showInputWidget: false, jump2CommentList: false, reverseFavorite: true);
              }
            },
            child: Padding(
              padding: EdgeInsets.only(left: Dimens.gap_view_biggest),
              child: SmallWidgets.buildImage(imageName: favorite?"ic_faved_normal":"ic_fav_normal", size: Dimens.view_item_icon_height_small),
            ),
          ),
        ],
      ),
    );
  }

  buildText(String data, Color color, double fontSize) {
    return SmallWidgets.buildText(data, color, fontSize, maxLines: 1);
  }
}
